#pragma once
#include <qbmessage/include/message_kernel.h>

#include <QDialog>

#include "FindPasswordDlg.h"
class QLabel;
class QVBoxLayout;
class ServerCombox;
class LoginProgressBtn;
class SImageButton;
class QrLoginWidget;
class SLineEdit;
class FadeTips;
class SCheckEx;
class FindPasswordDlg;
namespace qb {
class CAuthLoginImpl;
}

class StartupDlg : public QDialog,
                   public CUnknownObject<IMessageKernelObserver> {
  friend class QrLoginWidget;
  Q_OBJECT
 public:
  StartupDlg(QWidget* parent = nullptr);
  QWidget* serverList();

 Q_SIGNALS:
  void notifyProgress(int, int);
  void notifyErrorMsg(const QString& err);

 protected:
  virtual void paintEvent(QPaintEvent* event) override;
  virtual void resizeEvent(QResizeEvent*) override;

  virtual bool eventFilter(QObject* watched, QEvent* event) override;
  virtual void mousePressEvent(QMouseEvent* event) override;
  virtual void mouseReleaseEvent(QMouseEvent* event) override;
  virtual void mouseMoveEvent(QMouseEvent* event) override;
  virtual void keyPressEvent(QKeyEvent* event) override;
  void resetWidget();
  STDMETHOD_(void, OnRecvMsg)(char* pData, int nDataLen) {}
  STDMETHOD_(void, OnRecvNetStatus)(qb::NetStatus status, short retcode);

 protected Q_SLOTS:
  void onBtnClicked(int);
  void OnProgress(int progress, int result);  // TODO error!
  void showErrorMsg(const QString& err);
  void onClearPwd();

 private:
  void updateServerList();
  void login();
  void saveCfg();

 private:
  QVBoxLayout* m_leftLayout = nullptr;
  ServerCombox* m_cbServers = nullptr;
  LoginProgressBtn* m_loginBtn = nullptr;
  SImageButton* m_loginModeBtn = nullptr;
  SImageButton* m_loginSettingBtn = nullptr;
  bool m_loginByPwd = true;
  QWidget* m_loginSettingWidget = nullptr;
  QWidget* m_scanWidget = nullptr;
  SLineEdit* m_editUser = nullptr;
  SLineEdit* m_editPwd = nullptr;
  FadeTips* m_errTips = nullptr;
  SCheckEx* m_rememberPwd = nullptr;
  SCheckEx* m_autoStart = nullptr;
  bool m_dragging = false;
  QLabel* lbForget = nullptr;
};
